package cn.com.gridinfo.sooc.core.login.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import cn.com.gridinfo.sooc.R;
import cn.com.gridinfo.sooc.core.login.bean.NodeServerInfo;

/**
 * 选择学校界面的列表的适配器
 *
 * @author yingchunli
 */
public class NodeServerAdapter extends BaseAdapter {

    private Context context;
    private List<NodeServerInfo> list;

    public NodeServerAdapter(Context context, List<NodeServerInfo> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    private class ViewHolder {
        private TextView schoolName;//学校名称
        private View line;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.reg_school_item, null);

            viewHolder.schoolName = (TextView) convertView.findViewById(R.id.schoolName);
            viewHolder.line = convertView.findViewById(R.id.line);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        if (list.size() - 1 == position) {
            viewHolder.line.setVisibility(View.VISIBLE);
        } else {
            viewHolder.line.setVisibility(View.GONE);
        }
        viewHolder.schoolName.setText(list.get(position).getSqmc());
        return convertView;
    }
}
